/**
 * @Description : 用户文件信息表
 **/

const mongoose = require("mongoose");
const publicId = require("mongoose-public-id"); //自动生成容易识别的编码

const userFileSchema = new mongoose.Schema(
    {
        id: {
            //自动生成编码
            type: String,
            required: true,
            unique: true, //字段唯一
            default: ""
        },
        account: {
            //登录账号
            type: String,
            required: true
        },
        folder_id: {
            //文件夹ID
            type: String,
            required: false,
            default: ""
        },
        folder_name: {
            //所属文件夹名称
            type: String,
            required: true,
            default: ""
        },
        file_name: {
            //文件名称(重命名后的文件名)
            type: String,
            required: false,
            default: ""
        },
        file_old_name: {
            //文件原名称
            type: String,
            required: false,
            default: ""
        },
        file_type: {
            //文件类型:0,无;1,图片;2,文件
            type: Number,
            required: true,
            default: 0
        },
        file_suffix: {
            //文件后缀名称,如jpg/doc
            type: String,
            required: false,
            default: ""
        },
        file_size: {
            //文件大小,以字节为单位
            type: Number,
            required: true,
            default: 0
        },
        file_width: {
            //file_type=1,图片宽度
            type: Number,
            required: true,
            default: 0
        },
        file_height: {
            //file_type=1,图片高度
            type: Number,
            required: true,
            default: 0
        },
        file_url: {
            //文件路径
            type: String,
            required: false,
            default: ""
        },
        file_url_compress: {
            //压缩文件路径
            type: String,
            required: false,
            default: ""
        },
        file_compress_width: {
            //file_type=1,压缩图片宽度
            type: Number,
            required: true,
            default: 0
        },
        file_compress_height: {
            //file_type=1,压缩图片高度
            type: Number,
            required: true,
            default: 0
        },
        sort: {
            //排序
            type: Number,
            required: true,
            default: 0
        },
        memo: {
            //备注
            type: String,
            required: false,
            default: ""
        },
        status: {
            //数据记录状态（标志位）：0，删除；1，正常
            type: Number,
            required: true,
            default: 1
        },
        create_user: {
            //创建人
            type: String,
            required: true
        },
        create_time: {
            //创建时间
            type: String,
            required: true
        },
        update_user: {
            //更新人
            type: String,
            required: false,
            default: ""
        },
        update_time: {
            //更新时间
            type: String,
            required: false,
            default: ""
        },
        delete_user: {
            //删除人
            type: String,
            required: false,
            default: ""
        },
        delete_time: {
            //删除记录时间
            type: String,
            required: false,
            default: ""
        }
    },
    {
        versionKey: false
    }
);

//定义自动编码的组件，
userFileSchema.plugin(publicId, {
    namespace: "uf", // 前缀
    prefix: "_", // default value,
    fieldName: "id", //字段
    index: true // default value
});

// 参数:1,模型名称;2,对象;3,集合名称(collecttion)
module.exports = mongoose.model("user_files", userFileSchema, "user_files");
